﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ZeroBug.EasyFlow.Core
{
    public interface IStep
    {
        /// <summary>
        /// 只需要运行一次的步，如If,即使有子步，但是也只能执行一次
        /// </summary>
        bool IsSingleRun { get; set;}
        /// <summary>
        /// 控制是否执行子步,
        /// root步或空步，函数步，都是需要去执行子步的
        /// if while等条件步，首先看判断条件是否满足，满足了就去执行子步，否则不执行
        /// </summary>
        bool IgnoreChildren { get; set; }
        /// <summary>
        /// 是否是条件节点，如if的满足/不满足 switch的条件n
        /// 这些步骤再执行完他的子节点返回到该步是，需要再次返回到该步的父步
        /// </summary>
        //bool IsConditionNode { get; set; }
        string Icon { get; set; }
        int ChildrenIndex { get;set; }
        Step? NextStep { get; set; }
        object GetForm();
        /// <summary>
        /// 编辑时调用，看看本步有没有编译错误
        /// </summary>
        /// <param name="errInfo"></param>
        /// <returns></returns>
        bool Compile(FlowBase flow, Step step, out string errInfo);
        /// <summary>
        /// Flow Init时调用，准备好变量啥的
        /// </summary>
        /// <param name="errInfo"></param>
        /// <returns></returns>
        bool Prepare(FlowBase flow, Step step, out string errInfo);
        /// <summary>
        /// 运行
        /// </summary>
        /// <param name="errInfo"></param>
        /// <returns></returns>
        StepResult Run(FlowBase flow, Step step, out string errInfo);
        /// <summary>
        /// 提供本步的基础信息，供界面准备
        /// </summary>
        /// <returns></returns>
        StepInfo GetInfo();
        /// <summary>
        /// 本步的子步骤进入时调用
        /// </summary>
        void OnChildrenEnter();
        /// <summary>
        /// 本步的子步骤全部运行完成时调用
        /// </summary>
        void OnChildrenLeave();
        void RegisterVariables(FlowBase flow, Step step);
        void UnRegisterVariables(FlowBase flow, Step step);
        string GetTip(Step step);
        (SerializableDictionary<string, VariableExpression>, List<VariableJudge>) GetParametersAndConditions();
    }
}
